<template>
  <div class="main-content">
    <div class="main-container">
      <p class="base-title">
        <span class="dot"></span>移动端决策
      </p>
      <li class="otherLi">
        <div class="list-info-template companyName">
          <label class="control-label">{{companyName}}</label>
          <div class="control-detailsTwo">
            <div class="name">公司简称：</div>
            <Input placeholder="请输入内容"
                   v-model="companyAbbreviation"
                   clearable
                   :maxlength="8"
                   @input="radioChange('companyNameBtn')">
            </Input>
            <button class="btn btn-theme saveBtn"
                    hidden
                    id="companyNameBtn"
                    @click="saveChange(0)">保存</button>
          </div>
        </div>
      </li>
      <p class="base-title">
        <span class="dot"></span>全局决策
      </p>
      <li class="otherLi">
        <div class="list-info-template">
          <label class="control-label"
                 style="color: red;">允许重复报备</label>
          <div class="control-details">
            <RadioGroup v-model="repeatReport"
                        @on-change="radioChange('repeatReportBtn')">
              <Radio label="1">开启</Radio>
              <Radio label="0">关闭</Radio>
            </RadioGroup>
            <button class="btn btn-theme"
                    hidden
                    id="repeatReportBtn"
                    @click="saveChange(1)">保存</button>
          </div>
        </div>
        <p v-if="tempStatus.repeatReport==0">开启后，经纪人可针对同一楼盘的同一个客户进行多次报备</p>
        <p v-else>关闭后，经纪人针对同一楼盘的同一个客户只能报备一次</p>
        <div class="form-horizontal"
             style="margin-top: 15px;"
             v-if="repeatReport == 0 ? false : true">
          <div class="form-group">
            <label class="col-md-4 col-sm-2 control-label"
                   style="text-align: inherit;font-size: 16px;margin-right: -30px;">适用楼盘：</label>
            <div class="col-md-8 col-sm-10">
              <el-select v-model="repeatReportPremisesList"
                         @change='selectAll'
                         multiple
                         filterable
                         collapse-tags
                         placeholder="请选择"
                         style="width: 280px;">
                <el-option v-for="item in selectList"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
      </li>
      <li class="otherLi">
        <div class="list-info-template">
          <label class="control-label"
                 style="color: red;">允许报备免审</label>
          <div class="control-details">
            <RadioGroup v-model="freeAudit"
                        @on-change="radioChange('freeAuditBtn')">
              <Radio label="1">开启</Radio>
              <Radio label="0">关闭</Radio>
            </RadioGroup>
            <button class="btn btn-theme"
                    hidden
                    id="freeAuditBtn"
                    @click="saveChange(4)">保存</button>
          </div>
        </div>
        <p v-if="tempStatus.freeAudit==0">开启后，免审楼盘的所有报备无需校验,自动转为"未到访"状态</p>
        <p v-else>关闭后，所有楼盘都需要进行报备审核</p>
        <div class="form-horizontal"
             style="margin-top: 15px;"
             v-if="freeAudit == 0 ? false : true">
          <div class="form-group">
            <label class="col-md-4 col-sm-2 control-label"
                   style="text-align: inherit;font-size: 16px;margin-right: -30px;">适用楼盘：</label>
            <div class="col-md-8 col-sm-10">
              <el-select v-model="freeAuditPremisesList"
                         @change='selectFreeAuditAll'
                         multiple
                         filterable
                         collapse-tags
                         placeholder="请选择"
                         style="width: 280px;">
                <el-option v-for="item in selectFreeAuditList"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
      </li>
      <p class="base-title">
        <span class="dot"></span>移动端决策
      </p>
      <li class="otherLi">
        <div class="list-info-template">
          <label class="control-label">分销助手楼盘展示</label>
          <div class="control-details">
            <RadioGroup v-model="agencyIndexShow"
                        @on-change="radioChange('agencyIndexBtn')">
              <Radio label="1">开启</Radio>
              <Radio label="0">关闭</Radio>
            </RadioGroup>
            <button class="btn btn-theme"
                    hidden
                    id="agencyIndexBtn"
                    @click="saveChange(2)">保存</button>
          </div>
        </div>
        <p v-if="tempStatus.agencyIndexShow==0">开启后，分销助手端无需登录即可查看全部可售楼盘及详情，以起到推广楼盘的作用</p>
        <p v-else>关闭后，分销助手端需登录后才可查看全部可售楼盘及详情</p>
      </li>
      <div v-if="tempStatus.checkSwitchShow">
        <p class="base-title">
          <span class="dot"></span>报备号码验真服务
        </p>
        <li class="otherLi">
          <div class="list-info-template">
            <label class="control-label">允许短信验真</label>
            <div class="control-details">
              <RadioGroup v-model="checkSwitch"
                          @on-change="radioChange('checkSwitchBtn')">
                <Radio label="1">开启</Radio>
                <Radio label="0">关闭</Radio>
              </RadioGroup>
              <button class="btn btn-theme"
                      hidden
                      id="checkSwitchBtn"
                      @click="saveChange(3)">保存</button>
            </div>
          </div>
          <div class="form-horizontal"
               style="margin-top: 15px;"
               v-if="checkSwitch == 0 ? false : true">
            <div class="form-group">
              <label class="col-md-4 col-sm-2 control-label"
                     style="text-align: inherit;font-size: 16px;margin-right: -30px;">适用楼盘：</label>
              <div class="col-md-8 col-sm-10">
                <el-select v-model="checkSwitchPremisesList"
                           @change='selectCheckSwitchAll'
                           multiple
                           filterable
                           collapse-tags
                           placeholder="请选择"
                           style="width: 280px;">
                  <el-option v-for="item in selectCheckSwitchList"
                             :key="item.id"
                             :label="item.name"
                             :value="item.id">
                  </el-option>
                </el-select>
              </div>
            </div>
          </div>
        </li>
      </div>
      <div v-show="false">
        <p class="base-title"
           style="display:inline;">
          <span class="dot"></span>经纪人报备到期提醒时间
        </p>
        （每天上午9点，推送X天后即将到期的消息提醒（X为系统配置的天数），小于X天的即将到期不用提醒。）
        <li class="otherLi"
            style="display: list-item;">
          <div class="list-info-template">
            <input v-model="due_remainder_config.report_protect_remainder.due_remainder_id"
                   style="display:none;" />
            <label class="control-label"
                   style="min-width: 150px;">报备保护期到期提醒</label>
            <div class="control-details"
                 style="font-size: 15px;">
              <RadioGroup v-model="due_remainder_config.report_protect_remainder.remainder_switchs"
                          @on-change="showDueRemainderConfig('report_protect_remainder', 1)">
                <Radio label="1">开启</Radio>
                <Radio label="0">关闭</Radio>
              </RadioGroup>
              <span style="display:none;"
                    id="dueConfig1">
                &nbsp;&nbsp; &nbsp;&nbsp;提前&nbsp;&nbsp;
                <input type="number"
                       style="width: 75px; height: 23px;"
                       v-model="due_remainder_config.report_protect_remainder.advance_time"
                       @change="showDueRemainderConfig('report_protect_remainder', -1)" />
                &nbsp;&nbsp;天提醒消息
              </span>
              &nbsp;&nbsp;
              <button class="btn btn-theme"
                      hidden
                      id="report_protect_remainder"
                      @click="ensureSaveDueRemainderConfig(1, 'report_protect_remainder')">保存</button>
            </div>
          </div>
        </li>
        <li class="otherLi"
            style="display: list-item;">
          <div class="list-info-template">
            <input v-model="due_remainder_config.visit_protect_remainder.due_remainder_id"
                   style="display:none;" />
            <label class="control-label"
                   style="min-width: 150px;">到访保护期到期提醒</label>
            <div class="control-details"
                 style="font-size: 15px;">
              <RadioGroup v-model="due_remainder_config.visit_protect_remainder.remainder_switchs"
                          @on-change="showDueRemainderConfig('visit_protect_remainder', 2)">
                <Radio label="1">开启</Radio>
                <Radio label="0">关闭</Radio>
              </RadioGroup>
              <span style="display:none;"
                    id="dueConfig2">
                &nbsp;&nbsp;&nbsp;&nbsp;提前&nbsp;&nbsp;
                <input type="number"
                       style="width: 75px; height: 23px;"
                       v-model="due_remainder_config.visit_protect_remainder.advance_time"
                       @change="showDueRemainderConfig('visit_protect_remainder', -1)" />
                &nbsp;&nbsp;天提醒消息
              </span>
              &nbsp;&nbsp;
              <button class="btn btn-theme"
                      hidden
                      id="visit_protect_remainder"
                      @click="ensureSaveDueRemainderConfig(2, 'visit_protect_remainder')">保存</button>
            </div>
          </div>
        </li>
        <li class="otherLi"
            style="display: list-item;">
          <div class="list-info-template">
            <input v-model="due_remainder_config.unvisit_remainder.due_remainder_id"
                   style="display:none;" />
            <label class="control-label"
                   style="min-width: 150px;">超时未到访转无效提醒</label>
            <div class="control-details"
                 style="font-size: 15px;">
              <RadioGroup v-model="due_remainder_config.unvisit_remainder.remainder_switchs"
                          @on-change="showDueRemainderConfig('unvisit_remainder', 3)">
                <Radio label="1">开启</Radio>
                <Radio label="0">关闭</Radio>
              </RadioGroup>
              <span style="display:none;"
                    id="dueConfig3">
                &nbsp;&nbsp;&nbsp;&nbsp;提前&nbsp;&nbsp;
                <input type="number"
                       style="width: 75px; height: 23px;"
                       v-model="due_remainder_config.unvisit_remainder.advance_time"
                       @change="showDueRemainderConfig('unvisit_remainder', -1)"></input>
                &nbsp;&nbsp;天提醒消息
              </span>
              &nbsp;&nbsp;
              <button class="btn btn-theme"
                      hidden
                      id="unvisit_remainder"
                      @click="ensureSaveDueRemainderConfig(3, 'unvisit_remainder')">保存</button>
            </div>
          </div>
        </li>
        <li class="otherLi"
            style="display: list-item;">
          <div class="list-info-template">
            <input v-model="due_remainder_config.untrade_remainder.due_remainder_id"
                   style="display:none;" />
            <label class="control-label"
                   style="min-width: 150px;">超时未交易转无效提醒</label>
            <div class="control-details"
                 style="font-size: 15px;">
              <RadioGroup v-model="due_remainder_config.untrade_remainder.remainder_switchs"
                          @on-change="showDueRemainderConfig('untrade_remainder', 4)">
                <Radio label="1">开启</Radio>
                <Radio label="0">关闭</Radio>
              </RadioGroup>
              <span style="display:none;"
                    id="dueConfig4">
                &nbsp;&nbsp;&nbsp;&nbsp;提前&nbsp;&nbsp;
                <input type="number"
                       style="width: 75px; height: 23px;"
                       v-model="due_remainder_config.untrade_remainder.advance_time"
                       @change="showDueRemainderConfig('untrade_remainder', -1)"></input>
                &nbsp;&nbsp;天提醒消息
              </span>
              &nbsp;&nbsp;
              <button class="btn btn-theme"
                      hidden
                      id="untrade_remainder"
                      @click="ensureSaveDueRemainderConfig(4, 'untrade_remainder')">保存</button>
            </div>
          </div>
        </li>
      </div>
      <div v-if="enableWeapp">
        <p class="base-title">
          <span class="dot"></span>分销机构注册规则
        </p>
        <li class="otherLiTwo">
          <div class="list-info-templateTwo">
            <div class="topInfo">
              <label class="control-label">是否支持分销机构主动发起机构注册（需审核）</label>
              <button class="btn btn-theme registerBtn"
                      id="auditIndexBtn"
                      hidden
                      @click="saveChange(5)">保存</button>
            </div>
            <div class="control-details">
              <RadioGroup v-model="auditIndexShow"
                          @on-change="radioChange('auditIndexBtn')">
                <Radio label="1"
                       class="eachRadio">支持</Radio>
                <Radio label="0"
                       class="eachRadio">不支持</Radio>
              </RadioGroup>
            </div>
          </div>
        </li>
        <li class="otherLiTwo">
          <div class="list-info-templateTwo">
            <div class="topInfo">
              <label class="control-label">分销机构注册补充字段</label>
              <button class="btn btn-theme lastBtn"
                      id="supplementBtn"
                      hidden
                      @click="saveChange(6)">保存</button>
            </div>
            <div class="control-details">
              <div class="chooseItem"
                   v-for="(item,i) in supplementList">
                <Checkbox v-model="item.checked"
                          class="checkbox"
                          @on-change="radioChange('supplementBtn')">{{item.name}}
                </Checkbox>
                <span class="spanText"
                      v-if="item.name==='营业执照'">{{item.displayType | filterType(typeList)}}</span>
                <Select v-else
                        v-model="item.displayType"
                        class="select"
                        size="small"
                        @on-change="radioChange('supplementBtn')">
                  <Option v-for="ele in typeList"
                          :value="ele.id"
                          :key="ele.id">{{ ele.name }}</Option>
                </Select>
                <Select v-model="item.requiredStatus"
                        class="select"
                        size="small"
                        @on-change="radioChange('supplementBtn')">
                  <Option v-for="ele in requiredList"
                          :value="ele.id"
                          :key="ele.id">{{ ele.name }}</Option>
                </Select>
                <Icon type="ios-trash"
                      class="delete"
                      v-if="item.name!=='营业执照'"
                      @click="deleteAudit(i)" />
              </div>
              <div class="chooseItem addItem">
                <Input v-model="addAudit.name"
                       placeholder="名称"
                       size="small"
                       class="input"
                       :maxlength="10" />
                <Select v-model="addAudit.displayType"
                        class="select"
                        size="small">
                  <Option v-for="ele in typeList"
                          :value="ele.id"
                          :key="ele.id">{{ ele.name }}</Option>
                </Select>
                <Select v-model="addAudit.requiredStatus"
                        class="select"
                        size="small">
                  <Option v-for="ele in requiredList"
                          :value="ele.id"
                          :key="ele.id">{{ ele.name }}</Option>
                </Select>
                <Icon type="ios-add-circle-outline"
                      class="delete"
                      @click="addAuditContent" />
              </div>
            </div>
          </div>
        </li>
      </div>

    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      companyName: "",
      companyAbbreviation: "",
      agencyIndexShow: "0",
      auditIndexShow: "0",
      repeatReport: "0",
      checkSwitch: "0",
      freeAudit: "0",
      tempStatus: {
        agencyIndexShow: "0",
        repeatReport: "0",
        checkSwitch: "0",
        freeAudit: "0",
        checkSwitchShow: false
      },
      // 报备重复开关
      selectList: [{ id: "ALL_SELECT", name: "全选" }],
      oldChooseData: [],
      repeatReportPremisesList: [],
      // 报备验真开关
      selectCheckSwitchList: [{ id: "ALL_SELECT", name: "全选" }],
      oldCheckSwitchChooseData: [],
      checkSwitchPremisesList: [],
      // 报备免审开关
      selectFreeAuditList: [{ id: "ALL_SELECT", name: "全选" }],
      oldFreeAuditChooseData: [],
      freeAuditPremisesList: [],
      //报备到期提醒配置
      due_remainder_config: {
        report_protect_remainder: {
          due_remainder_id: 0,
          remainder_switchs: "0",
          advance_time: ""
        },
        visit_protect_remainder: {
          due_remainder_id: 0,
          remainder_switchs: "0",
          advance_time: ""
        },
        unvisit_remainder: {
          due_remainder_id: 0,
          remainder_switchs: "0",
          advance_time: ""
        },
        untrade_remainder: {
          due_remainder_id: 0,
          remainder_switchs: "0",
          advance_time: ""
        }
      },
      supplementList: [],
      initSupplementList: [],
      typeList: [
        { id: "0", name: "文本" },
        { id: "1", name: "图片" }
      ],
      requiredList: [
        { id: "1", name: "必填" },
        { id: "0", name: "选填" }
      ],
      addAudit: {
        name: "",
        displayType: null,
        requiredStatus: null
      },
      enableWeapp: false,
      modelResDtoList: []
    };
  },
  filters: {
    filterType(value, typeList) {
      if (!value) return "";
      return typeList.find((item) => {
        return item.id === value;
      }).name;
    }
  },
  mounted() {
    this.initDecision();
  },
  methods: {
    deleteAudit(index) {
      this.supplementList.splice(index, 1);
      $("#supplementBtn").show();
    },
    addAuditContent() {
      for (let value in this.addAudit) {
        if (!this.addAudit[value]) {
          layer.msg("请先补充完整信息");
          return;
        }
      }
      if (this.addAudit.name === "营业执照") {
        layer.msg("不能重复添加相同的字段");
        return;
      }
      this.supplementList.push({ ...this.addAudit, checked: false });
      this.addAudit = {
        name: "",
        displayType: null,
        requiredStatus: null
      };
      $("#supplementBtn").show();
    },
    selectAll(val) {
      const allValues = this.selectList.map((item) => {
        return item.id;
      });
      // 用来储存上一次选择的值，可进行对比
      const oldVal = this.oldChooseData.length > 0 ? this.oldChooseData : [];
      // 若选择全部
      if (val.includes("ALL_SELECT")) {
        this.repeatReportPremisesList = allValues;
      }
      // 取消全部选中， 上次有， 当前没有， 表示取消全选
      if (oldVal.includes("ALL_SELECT") && !val.includes("ALL_SELECT")) {
        this.repeatReportPremisesList = [];
      }
      // 点击非全部选中，需要排除全部选中 以及 当前点击的选项
      // 新老数据都有全部选中
      if (oldVal.includes("ALL_SELECT") && val.includes("ALL_SELECT")) {
        const index = val.indexOf("ALL_SELECT");
        val.splice(index, 1); // 排除全选选项
        this.repeatReportPremisesList = val;
      }
      // 全选未选，但是其他选项都全部选上了，则全选选上
      if (!oldVal.includes("ALL_SELECT") && !val.includes("ALL_SELECT")) {
        if (val.length === allValues.length - 1) {
          this.repeatReportPremisesList = ["ALL_SELECT"].concat(val);
        }
      }
      // 储存当前选择的最后结果 作为下次的老数据
      this.oldChooseData = this.repeatReportPremisesList;
      $("#repeatReportBtn").show();
    },
    selectCheckSwitchAll(val) {
      const allValues = this.selectCheckSwitchList.map((item) => {
        return item.id;
      });
      // 用来储存上一次选择的值，可进行对比
      const oldVal =
        this.oldCheckSwitchChooseData.length > 0
          ? this.oldCheckSwitchChooseData
          : [];
      // 若选择全部
      if (val.includes("ALL_SELECT")) {
        this.checkSwitchPremisesList = allValues;
      }
      // 取消全部选中， 上次有， 当前没有， 表示取消全选
      if (oldVal.includes("ALL_SELECT") && !val.includes("ALL_SELECT")) {
        this.checkSwitchPremisesList = [];
      }
      // 点击非全部选中，需要排除全部选中 以及 当前点击的选项
      // 新老数据都有全部选中
      if (oldVal.includes("ALL_SELECT") && val.includes("ALL_SELECT")) {
        const index = val.indexOf("ALL_SELECT");
        val.splice(index, 1); // 排除全选选项
        this.checkSwitchPremisesList = val;
      }
      // 全选未选，但是其他选项都全部选上了，则全选选上
      if (!oldVal.includes("ALL_SELECT") && !val.includes("ALL_SELECT")) {
        if (val.length === allValues.length - 1) {
          this.checkSwitchPremisesList = ["ALL_SELECT"].concat(val);
        }
      }
      // 储存当前选择的最后结果 作为下次的老数据
      this.oldCheckSwitchChooseData = this.checkSwitchPremisesList;
      $("#checkSwitchBtn").show();
    },
    selectFreeAuditAll(val) {
      const allValues = this.selectFreeAuditList.map((item) => {
        return item.id;
      });
      // 用来储存上一次选择的值，可进行对比
      const oldVal =
        this.oldFreeAuditChooseData.length > 0
          ? this.oldFreeAuditChooseData
          : [];
      // 若选择全部
      if (val.includes("ALL_SELECT")) {
        this.freeAuditPremisesList = allValues;
      }
      // 取消全部选中， 上次有， 当前没有， 表示取消全选
      if (oldVal.includes("ALL_SELECT") && !val.includes("ALL_SELECT")) {
        this.freeAuditPremisesList = [];
      }
      // 点击非全部选中，需要排除全部选中 以及 当前点击的选项
      // 新老数据都有全部选中
      if (oldVal.includes("ALL_SELECT") && val.includes("ALL_SELECT")) {
        const index = val.indexOf("ALL_SELECT");
        val.splice(index, 1); // 排除全选选项
        this.freeAuditPremisesList = val;
      }
      // 全选未选，但是其他选项都全部选上了，则全选选上
      if (!oldVal.includes("ALL_SELECT") && !val.includes("ALL_SELECT")) {
        if (val.length === allValues.length - 1) {
          this.freeAuditPremisesList = ["ALL_SELECT"].concat(val);
        }
      }
      // 储存当前选择的最后结果 作为下次的老数据
      this.oldFreeAuditChooseData = this.freeAuditPremisesList;
      $("#freeAuditBtn").show();
    },
    initDistribute() {
      var _self = this;
      var body = {};
      body.params = {};
      var url = this.utilHelper.apiUrl + "/api/getPremisesListByCompanyId";
      _self.$http.post(url, body).then(
        (response) => {
          var resData = response.body;
          if (resData.result != "1") {
            layer.msg("查询失败");
            return false;
          }
          // 重复报备决策模块
          let temArr = [];
          resData.resData.premisesList.forEach((item) => {
            temArr.push(item.id);
          });
          let flag = _self.equar(temArr, _self.repeatReportPremisesList);
          if (flag) {
            _self.repeatReportPremisesList.unshift("ALL_SELECT");
            _self.oldChooseData = _self.repeatReportPremisesList;
          }
          _self.selectList = [{ id: "ALL_SELECT", name: "全选" }];
          _self.selectList = _self.selectList.concat(
            resData.resData.premisesList
          );
          // 短信验真决策模块
          let checkSwitchTemArr = [];
          resData.resData.premisesList.forEach((item) => {
            checkSwitchTemArr.push(item.id);
          });
          let checkSwitchFlag = _self.equar(
            checkSwitchTemArr,
            _self.checkSwitchPremisesList
          );
          if (checkSwitchFlag) {
            _self.checkSwitchPremisesList.unshift("ALL_SELECT");
            _self.oldCheckSwitchChooseData = _self.checkSwitchPremisesList;
          }
          _self.selectCheckSwitchList = [{ id: "ALL_SELECT", name: "全选" }];
          _self.selectCheckSwitchList = _self.selectCheckSwitchList.concat(
            resData.resData.premisesList
          );
          // 报备免审决策模块
          let freeAuditTemArr = [];
          resData.resData.premisesList.forEach((item) => {
            freeAuditTemArr.push(item.id);
          });
          let freeAuditFlag = _self.equar(
            freeAuditTemArr,
            _self.freeAuditPremisesList
          );
          if (freeAuditFlag) {
            _self.freeAuditPremisesList.unshift("ALL_SELECT");
            _self.oldFreeAuditChooseData = _self.freeAuditPremisesList;
          }
          _self.selectFreeAuditList = [{ id: "ALL_SELECT", name: "全选" }];
          _self.selectFreeAuditList = _self.selectFreeAuditList.concat(
            resData.resData.premisesList
          );
        },
        (response) => {
          layer.msg("查询失败");
        }
      );
    },
    equar(a, b) {
      if (a.length !== b.length) {
        return false;
      }
      let m = new Map();
      a.forEach((o) => m.set(o, (m.get(o) || 0) + 1));
      b.forEach((o) => m.set(o, (m.get(o) || 0) - 1));
      for (var value of m.values()) {
        if (value !== 0) {
          return false;
        }
      }
      return true;
    },
    initDecision() {
      var _self = this;
      var body = {};
      body.params = {};
      var url = this.utilHelper.apiUrl + "/api/getAgencyIndexSwitch";
      _self.$http.post(url, body).then((response) => {
        if (response.body.result == "1") {
          var data = response.body.resData;
          _self.agencyIndexShow = data.agencyIndexSwitch;
          _self.tempStatus.agencyIndexShow = data.agencyIndexSwitch;
          _self.companyName = data.companyName;
          _self.companyAbbreviation = data.companyAbbreviation;
          _self.repeatReport = data.repeatReportSwitch;
          _self.tempStatus.repeatReport = data.repeatReportSwitch;
          _self.repeatReportPremisesList = data.repeatReportPremisesList
            ? data.repeatReportPremisesList
            : [];
          _self.checkSwitch = data.checkSwitch;
          _self.tempStatus.checkSwitch = data.checkSwitch;
          _self.tempStatus.checkSwitchShow = data.checkSwitchShow;
          _self.checkSwitchPremisesList = data.checkSwitchPremisesList
            ? data.checkSwitchPremisesList
            : [];
          _self.freeAudit = data.freeAudit;
          _self.tempStatus.freeAudit = data.freeAudit;
          _self.freeAuditPremisesList = data.freeAuditPremisesList
            ? data.freeAuditPremisesList
            : [];
          _self.enableWeapp = data.enableWeapp;
          _self.auditIndexShow = data.enableAgencyRegesit ? "1" : "0";
          _self.supplementList =
            (data.modelResDtoList &&
              data.modelResDtoList.map((item) => {
                return {
                  ...item,
                  checked: item.displayStatus === "1" ? true : false
                };
              })) ||
            [];
          _self.initSupplementList =
            (data.modelResDtoList &&
              data.modelResDtoList.map((item) => {
                return {
                  ...item,
                  checked: item.displayStatus === "1" ? true : false
                };
              })) ||
            [];
          //渲染消息到期提醒
          this.renderDueRemainderConfigInfo(data.dueRemainderConfigDtoList);

          this.initDistribute();
        }
      });
    },
    radioChange(type) {
      $("#" + type).show();
    },
    saveChange(type) {
      var _self = this;
      switch (type) {
        // 保存公司简称
        case 0:
          _self.saveCompanyName();
          break;
        // 重复报备
        case 1:
          _self.turnRepeat();
          break;
        // 分销助手首页楼盘展示
        case 2:
          _self.turnSwitch();
          break;
        // 验真短信决策
        case 3:
          _self.turnCheckSwitch();
          break;
        // 报备免审决策
        case 4:
          _self.turnFreeAudit();
          break;
        // 机构注册是否需要审核
        case 5:
          _self.turnRegisterAudit();
          break;
        // 机构注册补充字段
        case 6:
          _self.turnSupplement();
          break;
        default:
          break;
      }
    },
    saveCompanyName() {
      var url = this.utilHelper.apiUrl + "/api/updateCompanyAbbreviation";
      this.$http
        .post(url, {
          params: { companyAbbreviation: this.companyAbbreviation }
        })
        .then(
          (response) => {
            var result = response.body.result;
            if (result == 1) {
              layer.msg("保存成功");
              $("#companyNameBtn").hide();
            } else {
              layer.msg("保存失败");
            }
          },
          (response) => {
            layer.msg("保存失败");
          }
        );
    },
    turnSwitch() {
      var _self = this;
      let msg = _self.agencyIndexShow == "1" ? "开启" : "关闭";
      let recover = _self.agencyIndexShow == "1" ? "0" : "1";
      layer.confirm(
        "是否" + msg + "免登录查看楼盘",
        {
          btn: ["确定", "取消"],
          cancel() {
            _self.agencyIndexShow = recover;
            $("#agencyIndexBtn").hide();
          }
        },
        function (index) {
          var params = { agencyIndexSwitch: _self.agencyIndexShow };
          var body = {};
          body.params = params;
          var url = _self.utilHelper.apiUrl + "/api/changeAgencyIndexSwitch";
          _self.$http.post(url, body).then(
            (response) => {
              var data = response.body.resData;
              var result = data.result;
              var resultMsg = data.resultMsg;
              layer.close(index);
              if (result == 1) {
                layer.msg(msg + "成功");
                _self.tempStatus.agencyIndexShow = _self.agencyIndexShow;
                $("#agencyIndexBtn").hide();
              }
            },
            (response) => {}
          );
        },
        function () {
          _self.agencyIndexShow = recover;
          $("#agencyIndexBtn").hide();
        }
      );
    },
    turnRepeat() {
      var _self = this;
      if (_self.repeatReport == "1") {
        if (
          (_self.repeatReportPremisesList.indexOf("ALL_SELECT") == -1 &&
            _self.repeatReportPremisesList.length == 0) ||
          (_self.repeatReportPremisesList.indexOf("ALL_SELECT") != -1 &&
            _self.repeatReportPremisesList.length <= 1)
        ) {
          layer.msg("请选择适用楼盘！");
          return;
        }
      }
      if (_self.repeatReportPremisesList.indexOf("ALL_SELECT") != -1) {
        _self.repeatReportPremisesList.splice(
          _self.repeatReportPremisesList.indexOf("ALL_SELECT"),
          1
        );
      }

      let msg = _self.repeatReport == "1" ? "开启" : "关闭";
      let recover = _self.repeatReport == "1" ? "0" : "1";
      layer.confirm(
        "是否" + msg + "重复报备",
        {
          btn: ["确定", "取消"],
          cancel() {
            _self.repeatReport = recover;
            $("#repeatReportBtn").hide();
          }
        },
        function (index) {
          var params = {
            repeatReportSwitch: _self.repeatReport,
            repeatReportPremisesList: _self.repeatReportPremisesList
          };
          var body = {};
          body.params = params;
          var url = _self.utilHelper.apiUrl + "/api/changeAgencyIndexSwitch";
          _self.$http.post(url, body).then(
            (response) => {
              var data = response.body.resData;
              var result = data.result;
              var resultMsg = data.resultMsg;
              layer.close(index);
              if (result == 1) {
                _self.initDecision();
                layer.msg(msg + "成功");
                _self.tempStatus.repeatReport = _self.repeatReport;
                $("#repeatReportBtn").hide();
              }
            },
            (response) => {}
          );
        },
        function () {
          _self.repeatReport = recover;
          $("#repeatReportBtn").hide();
        }
      );
    },
    turnCheckSwitch() {
      var _self = this;
      if (_self.checkSwitch == "1") {
        if (
          (_self.checkSwitchPremisesList.indexOf("ALL_SELECT") == -1 &&
            _self.checkSwitchPremisesList.length == 0) ||
          (_self.checkSwitchPremisesList.indexOf("ALL_SELECT") != -1 &&
            _self.checkSwitchPremisesList.length <= 1)
        ) {
          layer.msg("请选择适用楼盘！");
          return;
        }
      }
      if (_self.checkSwitchPremisesList.indexOf("ALL_SELECT") != -1) {
        _self.checkSwitchPremisesList.splice(
          _self.checkSwitchPremisesList.indexOf("ALL_SELECT"),
          1
        );
      }

      let msg = _self.checkSwitch == "1" ? "开启" : "关闭";
      let recover = _self.checkSwitch == "1" ? "0" : "1";
      layer.confirm(
        "是否" + msg + "短信验真?",
        {
          btn: ["确定", "取消"],
          cancel() {
            _self.checkSwitch = recover;
            $("#checkSwitchBtn").hide();
          }
        },
        function (index) {
          var params = {
            checkSwitch: _self.checkSwitch,
            checkSwitchPremisesList: _self.checkSwitchPremisesList
          };
          var body = {};
          body.params = params;
          var url = _self.utilHelper.apiUrl + "/api/changeAgencyIndexSwitch";
          _self.$http.post(url, body).then(
            (response) => {
              var data = response.body.resData;
              var result = data.result;
              var resultMsg = data.resultMsg;
              layer.close(index);
              if (result == 1) {
                _self.initDecision();
                layer.msg(msg + "成功");
                _self.tempStatus.checkSwitch = _self.checkSwitch;
                $("#checkSwitchBtn").hide();
              }
            },
            (response) => {}
          );
        },
        function () {
          _self.checkSwitch = recover;
          $("#checkSwitchBtn").hide();
        }
      );
    },
    turnFreeAudit() {
      var _self = this;
      if (_self.freeAudit == "1") {
        if (
          (_self.freeAuditPremisesList.indexOf("ALL_SELECT") == -1 &&
            _self.freeAuditPremisesList.length == 0) ||
          (_self.freeAuditPremisesList.indexOf("ALL_SELECT") != -1 &&
            _self.freeAuditPremisesList.length <= 1)
        ) {
          layer.msg("请选择适用楼盘！");
          return;
        }
      }
      if (_self.freeAuditPremisesList.indexOf("ALL_SELECT") != -1) {
        _self.freeAuditPremisesList.splice(
          _self.freeAuditPremisesList.indexOf("ALL_SELECT"),
          1
        );
      }

      let msg = _self.freeAudit == "1" ? "开启" : "关闭";
      let recover = _self.freeAudit == "1" ? "0" : "1";
      layer.confirm(
        "是否" + msg + "报备免审?",
        {
          btn: ["确定", "取消"],
          cancel() {
            _self.freeAudit = recover;
            $("#freeAuditBtn").hide();
          }
        },
        function (index) {
          var params = {
            freeAudit: _self.freeAudit,
            freeAuditPremisesList: _self.freeAuditPremisesList
          };
          var body = {};
          body.params = params;
          var url = _self.utilHelper.apiUrl + "/api/changeAgencyIndexSwitch";
          _self.$http.post(url, body).then(
            (response) => {
              var data = response.body.resData;
              var result = data.result;
              var resultMsg = data.resultMsg;
              layer.close(index);
              if (result == 1) {
                _self.initDecision();
                layer.msg(msg + "成功");
                _self.tempStatus.freeAudit = _self.freeAudit;
                $("#freeAuditBtn").hide();
              }
            },
            (response) => {}
          );
        },
        function () {
          _self.freeAudit = recover;
          $("#freeAuditBtn").hide();
        }
      );
    },
    // 保存是否支持分销机构主动发起机构注册规则
    turnRegisterAudit() {
      var _self = this;
      const msg = this.auditIndexShow == "1" ? "支持" : "不支持";
      const init = this.auditIndexShow === "1" ? "0" : "1";
      layer.confirm(
        msg + "分销机构主动发起机构注册?",
        {
          btn: ["确定", "取消"],
          cancel() {
            this.auditIndexShow = init;
            $("#auditIndexBtn").hide();
          }
        },
        function (index) {
          var url =
            _self.utilHelper.apiUrl + "/api/saveAgentCompanyRegesitRule";
          _self.$http
            .post(url, {
              params: { enableAgentCompanyCheck: _self.auditIndexShow }
            })
            .then(
              (response) => {
                layer.close(index);
                if (response.body.result === "1") {
                  layer.msg("修改成功");
                  $("#auditIndexBtn").hide();
                } else {
                  layer.msg("修改失败");
                }
              },
              (response) => {}
            );
        },
        function () {
          _self.auditIndexShow = init;
          $("#auditIndexBtn").hide();
        }
      );
    },
    // 保存补充字段
    turnSupplement() {
      var _self = this;
      layer.confirm(
        "保存分销机构注册补充字段?",
        {
          btn: ["确定", "取消"],
          cancel() {
            _self.supplementList = _self.initSupplementList;
            $("#supplementBtn").hide();
          }
        },
        function (index) {
          var url = _self.utilHelper.apiUrl + "/api/saveModel";
          const data = _self.supplementList.map((item) => {
            return {
              name: item.name,
              displayType: item.displayType,
              displayStatus: item.checked ? "1" : "0",
              requiredStatus: item.requiredStatus,
              type: "1"
            };
          });
          _self.$http.post(url, { params: { modelReqDtoList: data } }).then(
            (response) => {
              if (response.body.result === "1") {
                layer.msg("修改成功");
                $("#supplementBtn").hide();
              } else {
                layer.msg("修改失败");
                $("#supplementBtn").hide();
              }
            },
            (response) => {}
          );
        },
        function () {
          _self.supplementList = _self.initSupplementList;
          $("#supplementBtn").hide();
        }
      );
    },
    // add by zilong.liu 消息到期提醒
    showDueRemainderConfig(ele1, type) {
      var _self = this;
      $("#" + ele1).show();
      switch (type) {
        case 1:
          if (
            _self.due_remainder_config.report_protect_remainder
              .remainder_switchs == 0
          ) {
            //_self.due_remainder_config.report_protect_remainder.advance_time = '';
            $("#dueConfig1").hide();
          } else {
            $("#dueConfig1").show();
          }
          break;
        case 2:
          if (
            _self.due_remainder_config.visit_protect_remainder
              .remainder_switchs == 0
          ) {
            // _self.due_remainder_config.visit_protect_remainder.advance_time = '';
            $("#dueConfig2").hide();
          } else {
            $("#dueConfig2").show();
          }
          break;
        case 3:
          if (
            _self.due_remainder_config.unvisit_remainder.remainder_switchs == 0
          ) {
            //_self.due_remainder_config.unvisit_remainder.advance_time = '';
            $("#dueConfig3").hide();
          } else {
            $("#dueConfig3").show();
          }
          break;
        case 4:
          if (
            _self.due_remainder_config.untrade_remainder.remainder_switchs == 0
          ) {
            //_self.due_remainder_config.untrade_remainder.advance_time = '';
            $("#dueConfig4").hide();
          } else {
            $("#dueConfig4").show();
          }
          break;
        default:
          break;
      }
    },
    ensureSaveDueRemainderConfig(type, ele) {
      var _self = this;
      _self.saveDueRemainderConfig(type, ele);
    },
    saveDueRemainderConfig(type, ele) {
      var _self = this;
      var due_remainder_id = 0;
      var remainder_switch = 0;
      var advance_time = "";
      var confirmContent = "";
      switch (type) {
        case 1:
          due_remainder_id =
            _self.due_remainder_config.report_protect_remainder
              .due_remainder_id;
          remainder_switch =
            _self.due_remainder_config.report_protect_remainder
              .remainder_switchs;
          advance_time =
            _self.due_remainder_config.report_protect_remainder.advance_time;
          confirmContent = "是否修改报备保护到期提醒规则";
          break;
        case 2:
          due_remainder_id =
            _self.due_remainder_config.visit_protect_remainder.due_remainder_id;
          remainder_switch =
            _self.due_remainder_config.visit_protect_remainder
              .remainder_switchs;
          advance_time =
            _self.due_remainder_config.visit_protect_remainder.advance_time;
          confirmContent = "是否修改到访保护到期提醒规则";
          break;
        case 3:
          due_remainder_id =
            _self.due_remainder_config.unvisit_remainder.due_remainder_id;
          remainder_switch =
            _self.due_remainder_config.unvisit_remainder.remainder_switchs;
          advance_time =
            _self.due_remainder_config.unvisit_remainder.advance_time;
          confirmContent = "是否修改超时未到访转无效提醒规则";
          break;
        case 4:
          due_remainder_id =
            _self.due_remainder_config.untrade_remainder.due_remainder_id;
          remainder_switch =
            _self.due_remainder_config.untrade_remainder.remainder_switchs;
          advance_time =
            _self.due_remainder_config.untrade_remainder.advance_time;
          confirmContent = "是否修改超时未交易转无效提醒规则";
          break;
        default:
          break;
      }
      var validateResult = _self.validateRemainderInfo(
        remainder_switch,
        advance_time
      );
      if (!validateResult) {
        layer.msg("请填写完整的规则信息！");
        return;
      }
      layer.confirm(
        confirmContent,
        {
          btn: ["确定", "取消"]
        },
        function (index) {
          var params = {
            dueRemainderId: due_remainder_id,
            remainderType: type,
            remainderSwitch: remainder_switch,
            advanceTime: advance_time,
            advanceTimeUnit: 1
          };
          var body = {};
          body.params = params;
          var url =
            _self.utilHelper.apiUrl + "/api/dueRemainderConfig/updateOrInsert";
          _self.$http.post(url, body).then(
            (response) => {
              var result = response.body.result;
              layer.close();
              if (result == "1") {
                _self.initDecision();
                $("#" + ele).hide();
                layer.msg("修改成功！");
                return;
              }
              layer.msg("修改失败，请稍后重试！");
            },
            (response) => {}
          );
        },
        function () {}
      );
    },
    //验证输入数据是否合法。当开启时，并且延期时间均选择，则为有效数据
    validateRemainderInfo(remainder_switch, advance_time) {
      if (remainder_switch > 0 && (advance_time < 0 || advance_time == "")) {
        return false;
      }
      return true;
    },
    renderDueRemainderConfigInfo(dueRemainderConfigDtoList) {
      var _self = this;
      for (var i = 0, j = dueRemainderConfigDtoList.length; i < j; i++) {
        var dueRemainderConfig = dueRemainderConfigDtoList[i];
        var remainder_type = dueRemainderConfig.remainderType;
        var due_remainder_id = dueRemainderConfig.dueRemainderId;
        var remainder_switchs = "" + dueRemainderConfig.remainderSwitch;
        var advance_time = dueRemainderConfig.advanceTime;
        if (remainder_switchs == "1") {
          $("#dueConfig" + remainder_type).show();
        } else {
          advance_time = "";
          $("#dueConfig" + remainder_type).hide();
        }
        switch (remainder_type) {
          case 1:
            _self.due_remainder_config.report_protect_remainder.due_remainder_id = due_remainder_id;
            _self.due_remainder_config.report_protect_remainder.remainder_switchs = remainder_switchs;
            _self.due_remainder_config.report_protect_remainder.advance_time = advance_time;
            break;
          case 2:
            _self.due_remainder_config.visit_protect_remainder.due_remainder_id = due_remainder_id;
            _self.due_remainder_config.visit_protect_remainder.remainder_switchs = remainder_switchs;
            _self.due_remainder_config.visit_protect_remainder.advance_time = advance_time;
            break;
          case 3:
            _self.due_remainder_config.unvisit_remainder.due_remainder_id = due_remainder_id;
            _self.due_remainder_config.unvisit_remainder.remainder_switchs = remainder_switchs;
            _self.due_remainder_config.unvisit_remainder.advance_time = advance_time;
            break;
          case 4:
            _self.due_remainder_config.untrade_remainder.due_remainder_id = due_remainder_id;
            _self.due_remainder_config.untrade_remainder.remainder_switchs = remainder_switchs;
            _self.due_remainder_config.untrade_remainder.advance_time = advance_time;
            break;
          default:
            break;
        }
      }
    }
    // add by zilong.liu 消息到期提醒
  }
};
</script>
<style lang="less">
.main-content .control-details .ivu-select-arrow {
  top: 80%;
}
</style>
<style scoped lang="less">
@import url("../../assets/css/multiple-select.css");
.base-title {
  font-weight: 700;
  font-style: normal;
  font-size: 18px;
  text-align: left;
  color: #000;
  margin-top: 20px;
  height: 33px;
  line-height: 33px;
}
.base-title .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #f87142;
  margin: 0 30px;
}
.base-title .tips {
  font-size: 13px;
  color: #999999;
  font-weight: normal;
  padding-left: 10px;
}
.list-info-templateTwo {
  .control-label {
    font-weight: normal !important;
    font-size: 15px;
    min-width: 10px;
    text-align: left;
    color: #000;
  }
}
.lastBtn {
  margin-left: 182px;
}
.registerBtn {
  margin-left: 16px;
}
.control-details {
  .eachRadio {
    margin: 10px 100px 0px 0;
  }
  .addItem {
    margin: 10px 0;
  }
  .input {
    margin-right: 5px;
    width: 130px;
  }
  .checkbox {
    width: 130px;
  }
  .select {
    width: 70px;
    margin-right: 5px;
  }
  .delete {
    font-size: 22px;
  }
  .spanText {
    width: 68px;
    display: inline-block;
  }
}
.list-info-template {
  padding-left: 150px !important;
}
.list-info-template .control-label {
  font-weight: normal !important;
  font-size: 15px;
  min-width: 170px;
  text-align: left;
  color: #000;
}
.list-info-template .form-control {
  height: 36px !important;
}
.list-info-template .control-details label {
  margin-right: 30px !important;
}
.list-info-template .control-detailsTwo {
  display: flex;
  align-items: center;
}
.list-info-template .name {
  width: 120px;
  font-size: 14px;
}
.companyName {
  line-height: 36px;
}
.list-info-template .saveBtn {
  margin-left: 20px;
  height: 27px;
}
.otherLi {
  display: inline-block;
  padding-top: 20px;
  padding-left: 60px;
}
.otherLiTwo {
  padding-top: 20px;
  padding-left: 60px;
}
</style>
